<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Created by PhpStorm.
 * User: zuoa
 * Date: 2016/11/21 0021
 * Time: 10:08
 */
class Position extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('position_model');
    }

    public function index()
    {
        $resp = array();
        $r = $this->position_model->get_today_checkin();
        foreach ($r as $p) {
            $area = $this->position_model->is_in_area($p["lng"], $p["lat"]);
            if (null == $resp["$area"]) {
                $resp["$area"] = array();
            }
            array_push($resp["$area"], $p);
        }

        $data["resp"] = $resp;

        $this->load->view('dashboard/position/index', $data);
    }

    public function export($month)
    {
        $csv = $this->position_model->get_month_export_simple($month);
        $this->output
            ->set_status_header(200)
            ->set_header('Content-disposition: filename="' . $month . '.csv"')
            ->set_content_type('application/csv', 'utf-8')
            ->set_output($csv)
            ->_display();
        die();
    }


    public function detail($month)
    {
        $csv = $this->position_model->get_month_export($month);
        $this->output
            ->set_status_header(200)
            ->set_header('Content-disposition: filename="' . $month . '.csv"')
            ->set_content_type('application/csv', 'utf-8')
            ->set_output($csv)
            ->_display();
        die();
    }


}